package apresentacao.caminhoneiro;

import controle.caminhoneiro.Controller_Conta;
import entidade.caminhoneiro.Caminhoneiro;
import tcc.caminhoneiro.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

public class Activity_Nova_Conta_Veiculo extends Activity{
	
	Spinner spVeiculo, spCarroceria;
	Button btCriar;
	Caminhoneiro caminhoneiro;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		caminhoneiro = (Caminhoneiro) getIntent().getExtras().getBundle("bundle").getSerializable("caminhoneiro");
		setContentView(R.layout.activity_nova_conta_veiculo);
		inicializar();
	}
	
	public void inicializar(){
		spVeiculo 		= (Spinner) findViewById(R.id.nova_conta_veiculo_spVeiculo);
		spCarroceria 	= (Spinner) findViewById(R.id.nova_conta_veiculo_spCarroceria);
		btCriar 		= (Button) findViewById(R.id.nova_conta_veiculo_btCriar);
		
		btCriar.setOnClickListener(eventoCriar);
		initCarroceria();
		initVeiculo();
	}
	
	OnClickListener eventoCriar = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			caminhoneiro.setCarroceria(spCarroceria.getSelectedItemPosition());
			caminhoneiro.setVeiculo(spVeiculo.getSelectedItemPosition());
			Controller_Conta controller = new Controller_Conta();
			controller.criarCaminhoneiro(caminhoneiro, Activity_Nova_Conta_Veiculo.this);
		}
	};
	
	public void initVeiculo(){
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.veiculos, android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spVeiculo.setAdapter(adapter);
	}
	
	public void initCarroceria(){
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.carrocerias, android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spCarroceria.setAdapter(adapter);		
	}

}
